package com.jifen.user.controller;

import com.jifen.common.CommonResult;
import com.jifen.common.Result;
import com.jifen.user.entity.User;
import com.jifen.user.service.UserService;
import com.jifen.user.vo.UserParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/jf/{version}/user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 注册
     * @param param
     * @return
     */
    @RequestMapping("/register")
    @ResponseBody
    public Result register(UserParam param) {
        userService.register(param);
        return CommonResult.createSuccessResult();
    }

    /**
     * 登录
     * @param param
     * @return
     */
    @RequestMapping("/login")
    @ResponseBody
    public Result login(UserParam param) {
        return CommonResult.createSuccessResult(userService.login(param.getMobile(), param.getPassword()));
    }

    /**
     * 注销
     * @param token
     * @return
     */
    @RequestMapping(value = "/logout")
    @ResponseBody
    public Result logout(String token) {
        userService.logout(token);
        return CommonResult.createSuccessResult();
    }

    /**
     * 找回密码
     * @param mobile
     * @param token
     * @param smsAuthcode
     * @param newPassword
     * @return
     */
    @RequestMapping("/forgetPassword")
    @ResponseBody
    public Result forgetPassword(String mobile, String token, String smsAuthcode, String newPassword) {
        userService.forgetPassword(mobile, token, smsAuthcode, newPassword);
        return CommonResult.createSuccessResult();
    }

    /**
     * 修改密码
     * @param token
     * @param oldPassword
     * @param newPassword
     * @return
     */
    @RequestMapping("/modifyPassword")
    @ResponseBody
    public Result modifyPassword(String token, String oldPassword, String newPassword) {
        userService.modifyPassword(token, oldPassword, newPassword);
        return CommonResult.createSuccessResult();
    }

    /**
     * 用户信息
     * @param token
     * @return
     */
    @RequestMapping(value = "/getUserInfo")
    @ResponseBody
    public Result getUserInfo(String token) {
        return CommonResult.createSuccessResult(userService.getUserInfo(token));
    }

    /**
     * 商家信息
     * @param token
     * @return
     */
    @RequestMapping(value = "/getMchInfo")
    @ResponseBody
    public Result getMchInfo(String token) {
        return CommonResult.createSuccessResult(userService.getMchInfo(token));
    }

    /**
     * 代理信息
     * @param token
     * @return
     */
    @RequestMapping(value = "/getAgentInfo")
    @ResponseBody
    public Result getAgentInfo(String token) {
        return CommonResult.createSuccessResult(userService.getAgentInfo(token));
    }

    /**
     * 扫描二维码
     * @param token
     * @param content
     * @return
     */
    @RequestMapping("/scanQrCode")
    @ResponseBody
    public Result scanQrCode(String token, String content) {
        return CommonResult.createSuccessResult(userService.scanQrCode(token, content));
    }

    /**
     * 确认积分交易
     * @param token
     * @param content
     * @return
     */
    @RequestMapping("/confirmTrade")
    @ResponseBody
    public Result confirmTrade(String token, String content) {
        userService.confirmTrade(token, content);
        return CommonResult.createSuccessResult();
    }

    /**
     * 积分明细
     * @param param
     * @return
     */
    @RequestMapping("/getJifenDetail")
    @ResponseBody
    public Result getJifenDetail(UserParam param) {
        return CommonResult.createSuccessResult(userService.getJifenDetail(param));
    }

    /**
     * 赠送积分
     * @param token
     * @param receiveMobile
     * @param smsAuthcode
     * @param jifen
     * @return
     */
    @RequestMapping(value = "/giveJifen")
    @ResponseBody
    public Result giveJifen(String token, String receiveMobile , String smsAuthcode, int jifen) {
        userService.giveJifen(token, receiveMobile, smsAuthcode, jifen);
        return CommonResult.createSuccessResult();
    }

    /**
     * 添加邀请人
     * @param token
     * @param inviterMobile
     * @return
     */
    @RequestMapping(value = "/addInviter")
    @ResponseBody
    public Result addInviter(String token, String inviterMobile) {
        userService.addInviter(token, inviterMobile);
        return CommonResult.createSuccessResult();
    }

    /**
     * 修改头像
     * @param token
     * @param user
     * @return
     */
    @RequestMapping(value = "/modifyHead")
    @ResponseBody
    public Result modifyHead(String token, User user) {
        userService.modifyHead(token, user);
        return CommonResult.createSuccessResult();
    }

    /**
     * 邀请收益
     * @param param
     * @return
     */
    @RequestMapping("/getInviteProfit")
    @ResponseBody
    public Result getInviteProfit(UserParam param) {
        return CommonResult.createSuccessResult(userService.getInviteProfit(param));
    }

    /**
     * 邀请商家收益明细
     * @param param
     * @return
     */
    @RequestMapping("/getInviteProfitDetail")
    @ResponseBody
    public Result getInviteProfitDetail(UserParam param) {
        return CommonResult.createSuccessResult(userService.getInviteProfitDetail(param));
    }

    /**
     * 邀请的商家
     * @param param
     * @return
     */
    @RequestMapping("/getInviteMchs")
    @ResponseBody
    public Result getInviteMchs(UserParam param) {
        return CommonResult.createSuccessResult(userService.getInviteMchs(param));
    }
}
